pro test2_miedist

  Nd = 100
  size_d0 = 5
  lambda = 0.4 ; um
  Cm=DComplex(1.33,-0.1)
  d0_arr = findgen(size_d0)*0.001 + 0.02; um
  logSg = 1.5
  Sg = Exp(logSg)
  Kxt=fltarr(size_d0)
  Kbk=fltarr(size_d0)
  Ksc=fltarr(size_d0)
  Bext=fltarr(size_d0)
  Bsca=fltarr(size_d0)
  w=fltarr(size_d0)
  g=fltarr(size_d0)
  for i=0,size_d0-1 do begin
    GenLogNormal,N_r,r,N=Nd,D0=d0_arr(i),logSigma=logSg
    Mie_dist,n_r,r,lambda,Cm,tmpKxt,tmpKsc,tmpKbk
    Kxt[i]=tmpKxt
    Kbk[i]=tmpKbk
    Ksc[i]=tmpKsc
    Mie_lognormal,Nd,d0_arr(i),Sg,lambda,Cm,iBext,iBsca,iw,ig;,ph
    Bext[i] = iBext
    Bsca[i] = iBsca
    w[i] = iw
    g[i] = ig
    print,'step',i,' done.'
  endfor
  print,'Kxt=',Kxt
  print,'Bext=',Bext
  plot,d0_arr,Kxt,/ylog
  oplot,d0_arr,Bext
  pic = tvrd()
;  write_png,'~/workspace/mie_compare.png',TVRD()
end
  
;  n_lambda=100
;  lambda = (findgen(n_lambda)+1)*0.1 ; um
;  Kxt=fltarr(n_lambda)
;  Kbk=fltarr(n_lambda)
;  Ksc=fltarr(n_lambda)
;  N = 100
;  d0=findgen(100)*0.01+0.04d
;  logSigma=1.5d
;  r = (findgen(100)+1)*0.01 ; um
;  n_r = LogNormal_r(N,d0,r,logSigma)
;  for i =0, n_lambda-1 do begin
;    Mie_dist,n_r,r,lambda[i],Cm,tmpKxt,tmpKsc,tmpKbk
;    Kxt[i]=tmpKxt
;    Kbk[i]=tmpKbk
;    Ksc[i]=tmpKsc
;  endfor
;  plot,lambda,Kxt,/xlog,/ylog
;  oplot,lambda,Kbk
;  oplot,lambda,Ksc,color='FFCC00'xl
;end

;if (N_params() eq 0) then begin
;  n_lambda=100
;  lambda = (findgen(n_lambda)+1)*0.1 ; um
;  Kxt=fltarr(n_lambda)
;  Kbk=fltarr(n_lambda)
;  Ksc=fltarr(n_lambda)
;  N = 100
;  d0=findgen(100)*0.01+0.04d
;  logSigma=1.5d
;endif else Cm=DComplex(mr,mi)
;r = (findgen(100)+1)*0.01 ; um
;n_r = LogNormal_r(N,d0,r,logSigma)
;for i =0, n_lambda-1 do begin
;  Mie_dist,n_r,r,lambda[i],Cm,tmpKxt,tmpKsc,tmpKbk
;  Kxt[i]=tmpKxt
;  Kbk[i]=tmpKbk
;  Ksc[i]=tmpKsc
;endfor
;plot,lambda,Kxt,/xlog,/ylog
;oplot,lambda,Kbk
;oplot,lambda,Ksc,color='FFCC00'xl
;end
